package com.game.betLottery.model;

import java.util.List;

import com.eova.common.base.BaseModel;
import com.jfinal.plugin.activerecord.Db;

public class Bet extends BaseModel<Bet> {
	/**
	 * TODO（用一句话描述这个变量表示什么）
	 */

	private static final long serialVersionUID = 1L;

	public static final Bet dao = new Bet();

	public List<Bet> getInfos(String roomId) {
		String sql = "select t.id as id,t.createTime as createTime,t.isWinning as isWinning,gu.headImgUrl as headImgUrl,gri.id as ruleId,gri.imgUrl as imgUrl,gu.nickName as nickName,gu.id as userId from game_detail_info t LEFT JOIN game_user gu ON t.userId = gu.id LEFT JOIN game_rule_info gri ON t.ruleId = gri.id where t.isOver=0 and t.roomId=?";
		return this.find(sql, roomId);
	}

	public int updateWin(String roomId, int resultKJ) {

		String delsql = "UPDATE game_detail_info SET isWinning = 1 WHERE roomId=? and ruleId=? ";
		int iRet = Db.update(delsql, roomId, resultKJ);// return 1 success
		return iRet;

	}

	/**
	 * 
	 * 描述:获取用户的信息 作者:gyp
	 */
	public Bet getInfo(String roomId, int resultKJ) {
		String sql = "select t.id as id,t.roomId as roomId,t.createTime as createTime,t.isWinning as isWinning,gu.headImgUrl as headImgUrl,gri.id as ruleId,gri.imgUrl as imgUrl,gri.unitPrice as unitPrice,gri.odds as odds,gu.nickName as nickName,gu.id as userId from game_detail_info t LEFT JOIN game_user gu ON t.userId = gu.id LEFT JOIN game_rule_info gri ON t.ruleId = gri.id where t.roomId=? and t.ruleId = ?";
		return this.findFirst(sql, roomId, resultKJ);
	}

	public int gameOver(String roomId) {

		String delsql = "UPDATE game_detail_info SET isOver = 1 WHERE roomId=? ";
		int iRet = Db.update(delsql, roomId);// return 1 success
		return iRet;

	}
}
